<?php

include(dirname(__FILE__).'/../../bootstrap/functional.php');

// create a new test browser
$browser = new sfTestBrowser();

/*
 * If a code_set_nm is not provided it should redirect to the codesetAdmin page
 */
$browser->
  get('/genCodeValueAdmin/index')->
  isStatusCode(302)->
  isRedirected()->   // Check that request is redirected
  followRedirect()->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'index');
 /*
  * Create a new code set TEST_GEN_SET
  */
$browser->
  get('/codesetAdmin/create')->
  isStatusCode(200)->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'create')->
  checkResponseElement('body', '/New/')->
  setField("cm_code_set[code_set_nm]","TEST_GEN_SET")->
  setField("cm_code_set[status_cd]","A")->
  setField("cm_code_set[class_cd]","GEN")->
  setField("cm_code_set[effective_from_time][year]","2003")-> 
  setField("cm_code_set[effective_from_time][month]","1")->
  setField("cm_code_set[effective_from_time][day]","1")->
  setField("cm_code_set[effective_to_time][year]","2010")-> 
  setField("cm_code_set[effective_to_time][month]","12")->
  setField("cm_code_set[effective_to_time][day]","31")->
  click('Save')->
  isRedirected()->   // Check that request is redirected
  followRedirect()->
  checkResponseElement('body', '/TEST_GEN_SET/');
  
/*
 * View code list of new code set and create first code.
 */
$browser->
  get('/genCodeValueAdmin/index/code_set_nm/TEST_GEN_SET')->
  isStatusCode(302)->
  isRedirected()->   // Check that request is redirected
  followRedirect()->
  isRequestParameter('module', 'genCodeValueAdmin')->
  isRequestParameter('action', 'new')->
  setField("cm_general_code_value[code_set_nm]", "TEST_GEN_SET")->
  setField("cm_general_code_value[code]", "TC")->
  setField("cm_general_code_value[description]", "This is the long description text.")->
  setField("cm_general_code_value[display_name]", "TEST_CODE")->
  setField("cm_general_code_value[status_cd]", "A")->
  click('Save')->
  isRedirected()->
  followRedirect()->
  isRequestParameter('module', 'genCodeValueAdmin')->
  isRequestParameter('action', 'show')->
  checkResponseElement('body', '/This is the long description text./');

/*
 * Try to create a duplicate code.
 */
$browser->
  get('/genCodeValueAdmin/new/code_set_nm/TEST_GEN_SET')->
  isRequestParameter('module', 'genCodeValueAdmin')->
  isRequestParameter('action', 'new')->
  setField("cm_general_code_value[code_set_nm]", "TEST_GEN_SET")->
  setField("cm_general_code_value[code]", "TC")->
  setField("cm_general_code_value[description]", "This is the long description text.")->
  setField("cm_general_code_value[display_name]", "TEST_CODE")->
  setField("cm_general_code_value[status_cd]", "A")->
  click('Save')->
  checkResponseElement('body', '/Code is already being used in this code set./');

/*
 * View code list of new code set and create first code.
 */
$browser->
  get('/genCodeValueAdmin/new/code_set_nm/TEST_GEN_SET')->
  isRequestParameter('module', 'genCodeValueAdmin')->
  isRequestParameter('action', 'new')->
  setField("cm_general_code_value[code_set_nm]", "TEST_GEN_SET")->
  setField("cm_general_code_value[code]", "ZZZ")->
  setField("cm_general_code_value[description]", "ZZZ this is the long description text.")->
  setField("cm_general_code_value[display_name]", "Second TEST CODE")->
  setField("cm_general_code_value[status_cd]", "A")->
  click('Save')->
  isRedirected()->
  followRedirect()->
  isRequestParameter('module', 'genCodeValueAdmin')->
  isRequestParameter('action', 'show')->
  checkResponseElement('body', '/ZZZ this is the long description text./');
  

/*
 * Delete Code Set and follow redirect to index page
 */
$browser->
  get('/codesetAdmin/delete/code_set_nm/TEST_GEN_SET')->
  isRedirected()->
  followRedirect()->
  isRequestParameter('module', 'codesetAdmin')->
  isRequestParameter('action', 'index');
  
  
  
  
